package com.yunkeji.api.gift.controller;

import com.yunkeji.api.gift.service.GiftService;
import com.yunkeji.api.gift.vo.GiftInfoVo;
import com.yunkeji.api.pay.bo.SendGiftBo;
import com.yunkeji.common.annotation.RepeatSubmit;
import com.yunkeji.common.core.controller.BaseController;
import com.yunkeji.common.core.domain.R;
import com.yunkeji.dao.domain.Gift;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
 * 礼物相关
 *
 * @author 老张
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/v1/gift")
public class GiftController extends BaseController {
    private final GiftService giftService;
    /** 获取礼物墙 */
    @PostMapping("/getGiftsWall")
    public R<List<GiftInfoVo>> getGiftsWall() {
        return R.ok(giftService.getGiftsWall());
    }

    /** 获取礼物列表 */
    @PostMapping("/getGiftsList")
    public R<List<Gift>> getGiftsList() {
        return R.ok(giftService.getGiftsList());
    }

    /** 打赏礼物 */
    @PostMapping("/sendGift")
    @RepeatSubmit(interval = 5, timeUnit = TimeUnit.SECONDS, message = "操作过快,五秒后再试")
    public R sendGift(@Valid @RequestBody SendGiftBo bo) {
        giftService.sendGift(bo);
        return R.ok("赠送成功");
    }
}
